package org.example.udemo3.service;

import org.example.udemo3.UserController.UserController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("org.example.udemo3")//添加扫描路径,它是一个数组,可以增加多个路径,用大括号括起来
@SpringBootApplication
public class Udemo3Application {



    public static void main(String[] args) {
        //获取Spring上下⽂对象
                SpringApplication.run(Udemo3Application.class, args);

//        UserController bean = context.getBean(UserController.class);
//        bean.say();
        //从Spring上下⽂中获取对象
//
//        //1.根据bean类型, 从Spring上下⽂中获取对象  使用于该类只有一个对象
//        UserController userController1 = context.getBean(UserController.class);
//
//        //2.根据bean名称, 从Spring上下⽂中获取对象  要进行类型的强转
//        UserController userController2 = (UserController)
//                context.getBean("userController");
//
//        //3.根据bean类型+名称, 从Spring上下⽂中获取对象
//        UserController userController3 =
//                context.getBean("userController",UserController.class);
//
//        System.out.println(userController1);
//        System.out.println(userController2);
//        System.out.println(userController3);//这三个对象都是同一个
//        UserService userService = context.getBean(UserService.class);

    }
}
